package com.zzuli.yxy.task.springDataPipeline;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzuli.yxy.entity.Song;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.zzuli.yxy.service.SongService;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 获取热歌榜歌曲
 * 将网易云歌曲id 和 歌名 存储到数据库中
 * @auther pony
 * @create 2023-04-04 11:59
 */
@Component
public class SongLyricPipeline implements Pipeline {
    @Autowired
    private SongService songService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        //1、获取封装好的歌词详情对象
        Song songLyric = resultItems.get("songLyric");
        System.out.println("存入数据库的歌曲信息："+ songLyric);
        //2、判断数据是否不为空
        if (songLyric!=null){
            LambdaUpdateWrapper<Song> uw = new LambdaUpdateWrapper<>();
            uw.eq(Song::getSongId, songLyric.getSongId());
            uw.set(Song::getSongLyric, songLyric.getSongLyric());
            songService.update(uw);
        }
    }
}
